{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-13T09:43:41.652468Z",
     "start_time": "2019-08-13T09:43:30.500254Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "迁移率数据写入完成！文件位置:D:\\迁移率\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "\n",
    "# 指定工作目录路径\n",
    "os.chdir('D:\\迁移率')\n",
    "data = pd.read_csv('qianyilv813.csv',low_memory=False)\n",
    "# data\n",
    "\n",
    "grant=['ZHONGAN','ZHAOLIAN','MASHANGXIAOJIN','WEIXIN','ZIZHUSHOUXIN','BESTPAY','GUOFU','DUMIAO','FENQICHAOREN','ZIYING','TIANCHENGRONGZU','YUANDONGRONGZU','YUEBAO']\n",
    "user =[1,2,3,4,5,10]\n",
    "area =['广东省','江苏省','重庆市','湖南省']\n",
    "\n",
    "for i in grant:\n",
    "    for j in user:\n",
    "        for k in area:\n",
    "            all = data.loc[(data['CREDIT_BY']==i)&(data['USER_TYPE']==j)&(data['ACCEPT_AREA_NAME']==k)].copy()\n",
    "            if all.shape[0] == 0:\n",
    "                pass\n",
    "            else:\n",
    "#                 print(all.shape)\n",
    "\n",
    "\n",
    "                # 转换时间\n",
    "                # all['REPAY_TIME4']=pd.to_datetime(all.REPAY_TIME4,format='%Y-%m-%d')\n",
    "                all['REPAY_TIME5']=pd.to_datetime(all.REPAY_TIME5,format='%Y-%m-%d')\n",
    "                all['REPAY_TIME6']=pd.to_datetime(all.REPAY_TIME6,format='%Y-%m-%d')\n",
    "                all['REPAY_TIME7']=pd.to_datetime(all.REPAY_TIME7,format='%Y-%m-%d')\n",
    "                all['REPAY_TIME8']=pd.to_datetime(all.REPAY_TIME8,format='%Y-%m-%d')\n",
    "                all['COMPLETE_TIME']=pd.to_datetime(all.COMPLETE_TIME,format='%Y-%m-%d').dt.month\n",
    "                # 按完成时间分类\n",
    "                # m3 = all[all['COMPLETE_TIME']==3]\n",
    "                m4 = all[all['COMPLETE_TIME']==4]\n",
    "                m5 = all[all['COMPLETE_TIME']==5]\n",
    "                m6 = all[all['COMPLETE_TIME']==6]\n",
    "                m7 = all[all['COMPLETE_TIME']==7]\n",
    "                m8 = all[all['COMPLETE_TIME']==8]\n",
    "                #4月\n",
    "                #按mob分类\n",
    "                #3月完成\n",
    "                # list_m3_t_4 = list(m3[m3['STATUS4']=='TERMINATE']['ACCOUNT_ID']) + list(m3[m3['STATUS4']=='CLOSE']['ACCOUNT_ID'])\n",
    "                # list_m3_m1_4 = list(m3[m3['REPAY_TIME4']>='2019-4-11']['ACCOUNT_ID'])+list(m3[m3['STATUS4']=='OPEN']['ACCOUNT_ID'])\n",
    "                # list_m3_c_4 = list(set(m3['ACCOUNT_ID']) ^ set(list_m3_t_4 + list_m3_m1_4))\n",
    "\n",
    "                # list_all_t_4 = list_m3_t_4\n",
    "                # list_all_m1_4 = list_m3_m1_4\n",
    "                list_all_c_4 = list(m4['ACCOUNT_ID'])\n",
    "                #5月\n",
    "                #按mob分类\n",
    "                #3月完成\n",
    "                # list_m3_t_5  = list(m3[m3['STATUS5']=='TERMINATE']['ACCOUNT_ID']) + list(m3[m3['STATUS5']=='CLOSE']['ACCOUNT_ID'])\n",
    "                # list_m3_m1_5 = list(m3[(m3['STATUS5']=='OPEN') & (m3['STATUS4']!='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME5']>='2019-5-11') & (m3['REPAY_TIME4']<'2019-5-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_m2_5 = list(m3[(m3['STATUS5']=='OPEN') & (m3['STATUS4']=='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME5']>='2019-5-11') & (m3['REPAY_TIME4']>='2019-5-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_c_5  = list(set(m3['ACCOUNT_ID']) ^ set(list_m3_t_5 + list_m3_m1_5 + list_m3_m2_5))\n",
    "\n",
    "\n",
    "                #4月完成\n",
    "                list_m4_t_5 = list(m4[m4['STATUS5']=='TERMINATE']['ACCOUNT_ID']) + list(m4[m4['STATUS5']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m4_m1_5 = list(m4[m4['STATUS5']=='OPEN']['ACCOUNT_ID']) + list(m4[m4['REPAY_TIME5']>='2019-5-11']['ACCOUNT_ID'])\n",
    "                list_m4_c_5  = list(set(m4['ACCOUNT_ID']) ^ set(list_m4_t_5 + list_m4_m1_5))\n",
    "\n",
    "                #总的\n",
    "                list_all_t_5  = list_m4_t_5\n",
    "                list_all_m1_5 = list_m4_m1_5\n",
    "\n",
    "                list_all_c_5  = list_m4_c_5 + list(m5['ACCOUNT_ID'])\n",
    "\n",
    "                #6月\n",
    "                #按mob分类\n",
    "                #3月完成\n",
    "                # list_m3_t_6  = list(m3[m3['STATUS6']=='TERMINATE']['ACCOUNT_ID']) + list(m3[m3['STATUS6']=='CLOSE']['ACCOUNT_ID'])\n",
    "                # list_m3_m1_6 = list(m3[(m3['STATUS6']=='OPEN') & (m3['STATUS5']!='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME6']>='2019-6-11') & (m3['REPAY_TIME5']<'2019-6-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_m2_6 = list(m3[(m3['STATUS6']=='OPEN') & (m3['STATUS5']=='OPEN') & (m3['STATUS4']!='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME6']>='2019-6-11') & (m3['REPAY_TIME5']>='2019-6-11') & (m3['REPAY_TIME4']<'2019-6-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_m3_6 = list(m3[(m3['STATUS6']=='OPEN') & (m3['STATUS5']=='OPEN') & (m3['STATUS4']=='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME6']>='2019-6-11') & (m3['REPAY_TIME5']>='2019-6-11') & (m3['REPAY_TIME4']>='2019-6-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_c_6  = list(set(m3['ACCOUNT_ID']) ^ set(list_m3_t_6 + list_m3_m1_6 + list_m3_m2_6 + list_m3_m3_6))\n",
    "\n",
    "                #4月完成\n",
    "                list_m4_t_6 = list(m4[m4['STATUS6']=='TERMINATE']['ACCOUNT_ID']) + list(m4[m4['STATUS6']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m4_m1_6 = list(m4[(m4['STATUS6']=='OPEN') & (m4['STATUS5']!='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME6']>='2019-6-11') & (m4['REPAY_TIME5']<'2019-6-11')]['ACCOUNT_ID'])\n",
    "                list_m4_m2_6 = list(m4[(m4['STATUS6']=='OPEN') & (m4['STATUS5']=='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME6']>='2019-6-11') & (m4['REPAY_TIME5']>='2019-6-11')]['ACCOUNT_ID'])\n",
    "                list_m4_c_6  = list(set(m4['ACCOUNT_ID']) ^ set(list_m4_t_6 + list_m4_m1_6 + list_m4_m2_6))\n",
    "                # 5月\n",
    "                list_m5_t_6  = list(m5[m5['STATUS6']=='TERMINATE']['ACCOUNT_ID']) + list(m5[m5['STATUS6']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m5_m1_6 = list(m5[m5['STATUS6']=='OPEN']['ACCOUNT_ID']) + list(m5[m5['REPAY_TIME6']>='2019-6-11']['ACCOUNT_ID'])\n",
    "                list_m5_c_6  = list(set(m5['ACCOUNT_ID']) ^ set(list_m5_t_6 + list_m5_m1_6))\n",
    "\n",
    "                #总的\n",
    "                list_all_t_6  = list_m4_t_6 + list_m5_t_6\n",
    "                list_all_m1_6 = list_m4_m1_6 + list_m5_m1_6\n",
    "                list_all_m2_6 = list_m4_m2_6\n",
    "\n",
    "                list_all_c_6  = list_m4_c_6 + list_m5_c_6 + list(m6['ACCOUNT_ID'])\n",
    "\n",
    "\n",
    "                #7月\n",
    "                #按mob分类\n",
    "                #3月完成\n",
    "                # list_m3_t_7  = list(m3[m3['STATUS7']=='TERMINATE']['ACCOUNT_ID']) + list(m3[m3['STATUS7']=='CLOSE']['ACCOUNT_ID'])\n",
    "                # list_m3_m1_7 = list(m3[(m3['STATUS7']=='OPEN') & (m3['STATUS6']!='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME7']>='2019-7-11') & (m3['REPAY_TIME6']<'2019-7-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_m2_7 = list(m3[(m3['STATUS7']=='OPEN') & (m3['STATUS6']=='OPEN') & (m3['STATUS5']!='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME7']>='2019-7-11') & (m3['REPAY_TIME6']>='2019-7-11') & (m3['REPAY_TIME5']<'2019-7-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_m3_7 = list(m3[(m3['STATUS7']=='OPEN') & (m3['STATUS6']=='OPEN') & (m3['STATUS5']=='OPEN')&(m3['STATUS4']!='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME7']>='2019-7-11') & (m3['REPAY_TIME6']>='2019-7-11') & (m3['REPAY_TIME5']>='2019-7-11') & (m3['REPAY_TIME4']<'2019-7-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_m4_7 = list(m3[(m3['STATUS7']=='OPEN') & (m3['STATUS6']=='OPEN') & (m3['STATUS5']=='OPEN')&(m3['STATUS4']=='OPEN')]['ACCOUNT_ID']) + list(m3[(m3['REPAY_TIME7']>='2019-7-11') & (m3['REPAY_TIME6']>='2019-7-11') & (m3['REPAY_TIME5']>='2019-7-11') & (m3['REPAY_TIME4']>='2019-7-11')]['ACCOUNT_ID'])\n",
    "                # list_m3_c_7  = list(set(m3['ACCOUNT_ID']) ^ set(list_m3_t_7 + list_m3_m1_7 + list_m3_m2_7 + list_m3_m3_7 + list_m3_m4_7))\n",
    "\n",
    "                #4月完成\n",
    "                list_m4_t_7  = list(m4[m4['STATUS7']=='TERMINATE']['ACCOUNT_ID']) + list(m4[m4['STATUS7']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m4_m1_7 = list(m4[(m4['STATUS7']=='OPEN') & (m4['STATUS6']!='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME7']>='2019-7-11') & (m4['REPAY_TIME6']<'2019-7-11')]['ACCOUNT_ID'])\n",
    "                list_m4_m2_7 = list(m4[(m4['STATUS7']=='OPEN') & (m4['STATUS6']=='OPEN') & (m4['STATUS5']!='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME7']>='2019-7-11') & (m4['REPAY_TIME6']>='2019-7-11') & (m4['REPAY_TIME5']<'2019-7-11')]['ACCOUNT_ID'])\n",
    "                list_m4_m3_7 = list(m4[(m4['STATUS7']=='OPEN') & (m4['STATUS6']=='OPEN') & (m4['STATUS5']=='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME7']>='2019-7-11') & (m4['REPAY_TIME6']>='2019-7-11') & (m4['REPAY_TIME5']>='2019-7-11')]['ACCOUNT_ID'])\n",
    "                list_m4_c_7  = list(set(m4['ACCOUNT_ID']) ^ set(list_m4_t_7 + list_m4_m1_7 + list_m4_m2_7 + list_m4_m3_7))\n",
    "\n",
    "                #5月完成\n",
    "                list_m5_t_7  = list(m5[m5['STATUS7']=='TERMINATE']['ACCOUNT_ID']) + list(m5[m5['STATUS7']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m5_m1_7 = list(m5[(m5['STATUS7']=='OPEN') & (m5['STATUS6']!='OPEN')]['ACCOUNT_ID']) + list(m5[(m5['REPAY_TIME7']>='2019-7-11') & (m5['REPAY_TIME6']<'2019-7-11')]['ACCOUNT_ID'])\n",
    "                list_m5_m2_7 = list(m5[(m5['STATUS7']=='OPEN') & (m5['STATUS6']=='OPEN')]['ACCOUNT_ID']) + list(m5[(m5['REPAY_TIME7']>='2019-7-11') & (m5['REPAY_TIME6']>='2019-7-11')]['ACCOUNT_ID'])\n",
    "                list_m5_c_7  = list(set(m5['ACCOUNT_ID']) ^ set(list_m5_t_7 + list_m5_m1_7 + list_m5_m2_7))\n",
    "\n",
    "                #6月完成\n",
    "                list_m6_t_7  = list(m6[m6['STATUS7']=='TERMINATE']['ACCOUNT_ID']) + list(m6[m6['STATUS7']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m6_m1_7 = list(m6[(m6['STATUS7']=='OPEN')]['ACCOUNT_ID']) + list(m6[(m6['REPAY_TIME7']>='2019-7-11')]['ACCOUNT_ID'])\n",
    "                list_m6_c_7  = list(set(m6['ACCOUNT_ID']) ^ set(list_m6_t_7 + list_m6_m1_7))\n",
    "\n",
    "                #总的\n",
    "                list_all_t_7 = list_m4_t_7 + list_m5_t_7 + list_m6_t_7\n",
    "                list_all_m1_7 = list_m4_m1_7 + list_m5_m1_7 + list_m6_m1_7\n",
    "                list_all_m2_7 = list_m4_m2_7 + list_m5_m2_7\n",
    "                list_all_m3_7 = list_m4_m3_7\n",
    "\n",
    "                list_all_c_7  = list_m4_c_7 + list_m5_c_7 + list_m6_c_7 + list(m7['ACCOUNT_ID'])\n",
    "                \n",
    "                \n",
    "                #8月\n",
    "                #按mob分类\n",
    "\n",
    "                #4月完成\n",
    "                list_m4_t_8  = list(m4[m4['STATUS8']=='TERMINATE']['ACCOUNT_ID']) + list(m4[m4['STATUS8']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m4_m1_8 = list(m4[(m4['STATUS8']=='OPEN') & (m4['STATUS7']!='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME8']>='2019-8-11') & (m4['REPAY_TIME7']<'2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m4_m2_8 = list(m4[(m4['STATUS8']=='OPEN') & (m4['STATUS7']=='OPEN') & (m4['STATUS6']!='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME8']>='2019-8-11') & (m4['REPAY_TIME7']>='2019-8-11') & (m4['REPAY_TIME6']<'2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m4_m3_8 = list(m4[(m4['STATUS8']=='OPEN') & (m4['STATUS7']=='OPEN') & (m4['STATUS6']=='OPEN') & (m4['STATUS5']!='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME8']>='2019-8-11') & (m4['REPAY_TIME7']>='2019-8-11') & (m4['REPAY_TIME6']>='2019-8-11') & (m4['REPAY_TIME5']<'2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m4_m4_8 = list(m4[(m4['STATUS8']=='OPEN') & (m4['STATUS7']=='OPEN') & (m4['STATUS6']=='OPEN') & (m4['STATUS5']=='OPEN')]['ACCOUNT_ID']) + list(m4[(m4['REPAY_TIME8']>='2019-8-11') & (m4['REPAY_TIME7']>='2019-8-11') & (m4['REPAY_TIME6']>='2019-8-11') & (m4['REPAY_TIME5']>='2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m4_c_8  = list(set(m4['ACCOUNT_ID']) ^ set(list_m4_t_8 + list_m4_m1_8 + list_m4_m2_8 + list_m4_m3_8 + list_m4_m4_8))\n",
    "\n",
    "                #5月完成\n",
    "                list_m5_t_8  = list(m5[m5['STATUS8']=='TERMINATE']['ACCOUNT_ID']) + list(m5[m5['STATUS8']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m5_m1_8 = list(m5[(m5['STATUS8']=='OPEN') & (m5['STATUS7']!='OPEN')]['ACCOUNT_ID']) + list(m5[(m5['REPAY_TIME8']>='2019-8-11') & (m5['REPAY_TIME7']<'2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m5_m2_8 = list(m5[(m5['STATUS8']=='OPEN') & (m5['STATUS7']=='OPEN') & (m5['STATUS6']!='OPEN')]['ACCOUNT_ID']) + list(m5[(m5['REPAY_TIME8']>='2019-8-11') & (m5['REPAY_TIME7']>='2019-8-11') & (m5['REPAY_TIME6']<'2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m5_m3_8 = list(m5[(m5['STATUS8']=='OPEN') & (m5['STATUS7']=='OPEN') & (m5['STATUS6']=='OPEN')]['ACCOUNT_ID']) + list(m5[(m5['REPAY_TIME8']>='2019-8-11') & (m5['REPAY_TIME7']>='2019-8-11') & (m5['REPAY_TIME6']>='2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m5_c_8  = list(set(m5['ACCOUNT_ID']) ^ set(list_m5_t_8 + list_m5_m1_8 + list_m5_m2_8 + list_m5_m3_8))\n",
    "\n",
    "                #6月完成\n",
    "                list_m6_t_8  = list(m6[m6['STATUS8']=='TERMINATE']['ACCOUNT_ID']) + list(m6[m6['STATUS8']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m6_m1_8 = list(m6[(m6['STATUS8']=='OPEN') & (m6['STATUS7']!='OPEN')]['ACCOUNT_ID']) + list(m6[(m6['REPAY_TIME8']>='2019-8-11') & (m6['REPAY_TIME7']<'2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m6_m2_8 = list(m6[(m6['STATUS8']=='OPEN') & (m6['STATUS7']=='OPEN')]['ACCOUNT_ID']) + list(m6[(m6['REPAY_TIME8']>='2019-8-11') & (m6['REPAY_TIME7']>='2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m6_c_8  = list(set(m6['ACCOUNT_ID']) ^ set(list_m6_t_8 + list_m6_m1_8 + list_m6_m2_8))\n",
    "\n",
    "                #7月完成\n",
    "                list_m7_t_8  = list(m7[m7['STATUS8']=='TERMINATE']['ACCOUNT_ID']) + list(m7[m7['STATUS8']=='CLOSE']['ACCOUNT_ID'])\n",
    "                list_m7_m1_8 = list(m7[(m7['STATUS8']=='OPEN')]['ACCOUNT_ID']) + list(m7[(m7['REPAY_TIME8']>='2019-8-11')]['ACCOUNT_ID'])\n",
    "                list_m7_c_8  = list(set(m7['ACCOUNT_ID']) ^ set(list_m7_t_8 + list_m7_m1_8))\n",
    "\n",
    "                #总的\n",
    "                list_all_t_8 = list_m4_t_8 + list_m5_t_8 + list_m6_t_8 + list_m7_t_8\n",
    "                list_all_m1_8 = list_m4_m1_8 + list_m5_m1_8 + list_m6_m1_8 + list_m7_m1_8\n",
    "                list_all_m2_8 = list_m4_m2_8 + list_m5_m2_8 + list_m6_m2_8\n",
    "                list_all_m3_8 = list_m4_m3_8 + list_m5_m3_8\n",
    "                list_all_m4_8 = list_m4_m4_8\n",
    "\n",
    "                list_all_c_8  = list_m4_c_8 + list_m5_c_8 + list_m6_c_8 + list_m7_c_8 + list(m8['ACCOUNT_ID'])\n",
    "                \n",
    "                \n",
    "\n",
    "                # 计算结果保存\n",
    "                # C-M1\n",
    "                # c_m1_04_z = len(list_all_m1_4)\n",
    "                # c_m1_04_m = m3.shape[0]\n",
    "                c_m1_05_z = len(set(list_all_m1_5)&set(list_all_c_4))\n",
    "                c_m1_05_m = len(list_all_c_4)\n",
    "                c_m1_06_z = len(set(list_all_m1_6)&set(list_all_c_5))\n",
    "                c_m1_06_m = len(list_all_c_5)\n",
    "                c_m1_07_z = len(set(list_all_m1_7)&set(list_all_c_6))\n",
    "                c_m1_07_m = len(list_all_c_6)\n",
    "                c_m1_08_z = len(set(list_all_m1_8)&set(list_all_c_7))\n",
    "                c_m1_08_m = len(list_all_c_7)\n",
    "\n",
    "\n",
    "                # M1-M2\n",
    "                # m1_m2_05_z = len(list_all_m2_5)\n",
    "                # m1_m2_05_m = len(list_all_m1_4)\n",
    "                m1_m2_06_z = len(set(list_all_m2_6)&set(list_all_m1_5))\n",
    "                m1_m2_06_m = len(list_all_m1_5)\n",
    "                m1_m2_07_z = len(set(list_all_m2_7)&set(list_all_m1_6))\n",
    "                m1_m2_07_m = len(list_all_m1_6)\n",
    "                m1_m2_08_z = len(set(list_all_m2_8)&set(list_all_m1_7))\n",
    "                m1_m2_08_m = len(list_all_m1_7)\n",
    "\n",
    "                # M2-M3\n",
    "                # m2_m3_06_z = len(list_all_m3_6)\n",
    "                # m2_m3_06_m = len(list_all_m2_5)\n",
    "                m2_m3_07_z = len(set(list_all_m3_7)&set(list_all_m2_6))\n",
    "                m2_m3_07_m = len(list_all_m2_6)\n",
    "                m2_m3_08_z = len(set(list_all_m3_8)&set(list_all_m2_7))\n",
    "                m2_m3_08_m = len(list_all_m2_7)\n",
    "\n",
    "                # M3-M4\n",
    "                m3_m4_08_z = len(set(list_all_m4_8)&set(list_all_m3_7))\n",
    "                m3_m4_08_m = len(list_all_m3_7)\n",
    "\n",
    "\n",
    "                # C-M2\n",
    "                # c_m2_05_z = c_m1_04_z * m1_m2_05_z\n",
    "                # c_m2_05_m = c_m1_04_m * m1_m2_05_m\n",
    "                c_m2_06_z = c_m1_05_z * m1_m2_06_z\n",
    "                c_m2_06_m = c_m1_05_m * m1_m2_06_m\n",
    "                c_m2_07_z = c_m1_06_z * m1_m2_07_z\n",
    "                c_m2_07_m = c_m1_06_m * m1_m2_07_m\n",
    "                c_m2_08_z = c_m1_07_z * m1_m2_08_z\n",
    "                c_m2_08_m = c_m1_07_m * m1_m2_08_m\n",
    "\n",
    "                # C-M3\n",
    "\n",
    "                c_m3_07_z = c_m1_05_z * m1_m2_06_z * m2_m3_07_z\n",
    "                c_m3_07_m = c_m1_05_m * m1_m2_06_m * m2_m3_07_m\n",
    "                c_m3_08_z = c_m1_06_z * m1_m2_07_z * m2_m3_08_z\n",
    "                c_m3_08_m = c_m1_06_m * m1_m2_07_m * m2_m3_08_m\n",
    "\n",
    "                # C-M4\n",
    "                c_m4_08_z = c_m1_05_z * m1_m2_06_z * m2_m3_07_z * m3_m4_08_z\n",
    "                c_m4_08_m = c_m1_05_m * m1_m2_06_m * m2_m3_07_m * m3_m4_08_m\n",
    "\n",
    "\n",
    "                #C-C\n",
    "\n",
    "                c_c_05_z = len(set(list_all_c_4)&set(list_all_c_5))\n",
    "                c_c_05_m = len(set(list_all_c_4))\n",
    "                c_c_06_z = len(set(list_all_c_6)&set(list_all_c_5))\n",
    "                c_c_06_m = len(set(list_all_c_5))\n",
    "                c_c_07_z = len(set(list_all_c_7)&set(list_all_c_6))\n",
    "                c_c_07_m = len(set(list_all_c_6))\n",
    "                c_c_08_z = len(set(list_all_c_8)&set(list_all_c_7))\n",
    "                c_c_08_m = len(set(list_all_c_7))\n",
    "                #M1-C\n",
    "\n",
    "                m1_c_06_z = len(set(list_all_m1_5)&set(list_all_c_6))\n",
    "                m1_c_06_m = len(set(list_all_m1_5))\n",
    "                m1_c_07_z = len(set(list_all_m1_6)&set(list_all_c_7))\n",
    "                m1_c_07_m = len(set(list_all_m1_6))\n",
    "                m1_c_08_z = len(set(list_all_m1_7)&set(list_all_c_8))\n",
    "                m1_c_08_m = len(set(list_all_m1_7))\n",
    "                #M2-C\n",
    "\n",
    "                m2_c_07_z = len(set(list_all_m2_6)&set(list_all_c_7))\n",
    "                m2_c_07_m = len(list_all_m2_6)\n",
    "                m2_c_08_z = len(set(list_all_m2_7)&set(list_all_c_8))\n",
    "                m2_c_08_m = len(list_all_m2_7)\n",
    "                # M3-C\n",
    "                m3_c_08_z = len(set(list_all_m3_7)&set(list_all_c_8))\n",
    "                m3_c_08_m = len(list_all_m3_7)\n",
    "                #M1-M1\n",
    "\n",
    "                m1_m1_06_z = len(set(list_all_m1_6)&set(list_all_m1_5))\n",
    "                m1_m1_06_m = len(set(list_all_m1_5))\n",
    "                m1_m1_07_z = len(set(list_all_m1_7)&set(list_all_m1_6))\n",
    "                m1_m1_07_m = len(set(list_all_m1_6))\n",
    "                m1_m1_08_z = len(set(list_all_m1_8)&set(list_all_m1_7))\n",
    "                m1_m1_08_m = len(set(list_all_m1_7))\n",
    "\n",
    "                #M2-M1\n",
    "\n",
    "                m2_m1_07_z = len(set(list_all_m2_6)&set(list_all_m1_7))\n",
    "                m2_m1_07_m = len(set(list_all_m2_6))\n",
    "                m2_m1_08_z = len(set(list_all_m2_7)&set(list_all_m1_8))\n",
    "                m2_m1_08_m = len(set(list_all_m2_7))\n",
    "\n",
    "                # M3-M1\n",
    "                m3_m1_08_z = len(set(list_all_m3_7)&set(list_all_m1_8))\n",
    "                m3_m1_08_m = len(list_all_m3_7)\n",
    "\n",
    "                # 数据写入到文件\n",
    "                with open('迁移率(10号)导出.txt', 'a+') as f:\n",
    "                    # C-M1\n",
    "                    c_m1_5 = \"{},{},{},C-M1,201905,{},{}\".format(i,j,k,c_m1_05_z,c_m1_05_m)\n",
    "                    c_m1_6 = \"{},{},{},C-M1,201906,{},{}\".format(i,j,k,c_m1_06_z,c_m1_06_m)\n",
    "                    c_m1_7 = \"{},{},{},C-M1,201907,{},{}\".format(i,j,k,c_m1_07_z,c_m1_07_m)\n",
    "                    c_m1_8 = \"{},{},{},C-M1,201908,{},{}\".format(i,j,k,c_m1_08_z,c_m1_08_m)\n",
    "                    f.write(c_m1_5+'\\n'+c_m1_6+'\\n'+c_m1_7+'\\n'+c_m1_8+'\\n')\n",
    "\n",
    "                    # M1-M2\n",
    "                    m1_m2_6 = \"{},{},{},M1-M2,201906,{},{}\".format(i,j,k,m1_m2_06_z,m1_m2_06_m)\n",
    "                    m1_m2_7 = \"{},{},{},M1-M2,201907,{},{}\".format(i,j,k,m1_m2_07_z,m1_m2_07_m)\n",
    "                    m1_m2_8 = \"{},{},{},M1-M2,201908,{},{}\".format(i,j,k,m1_m2_08_z,m1_m2_08_m)\n",
    "\n",
    "                    f.write(m1_m2_6+'\\n'+m1_m2_7+'\\n'+m1_m2_8+'\\n')\n",
    "\n",
    "                    # M2-M3\n",
    "                    m2_m3_7 = \"{},{},{},M2-M3,201907,{},{}\".format(i,j,k,m2_m3_07_z,m2_m3_07_m)\n",
    "                    m2_m3_8 = \"{},{},{},M2-M3,201908,{},{}\".format(i,j,k,m2_m3_08_z,m2_m3_08_m)\n",
    "\n",
    "                    f.write(m2_m3_7+'\\n'+m2_m3_8+'\\n')\n",
    "\n",
    "                    # M3-M4\n",
    "                    m3_m4_8 = \"{},{},{},M3-M4,201908,{},{}\".format(i,j,k,m3_m4_08_z,m3_m4_08_m)\n",
    "\n",
    "                    f.write(m3_m4_8+'\\n')\n",
    "\n",
    "                    # C-M2\n",
    "                    c_m2_6 = \"{},{},{},C-M2,201906,{},{}\".format(i,j,k,c_m2_06_z,c_m2_06_m)\n",
    "                    c_m2_7 = \"{},{},{},C-M2,201907,{},{}\".format(i,j,k,c_m2_07_z,c_m2_07_m)\n",
    "                    c_m2_8 = \"{},{},{},C-M2,201908,{},{}\".format(i,j,k,c_m2_08_z,c_m2_08_m)\n",
    "\n",
    "                    f.write(c_m2_6+'\\n'+c_m2_7+'\\n'+c_m2_8+'\\n')\n",
    "\n",
    "                    # C-M3\n",
    "                    c_m3_7 = \"{},{},{},C-M3,201907,{},{}\".format(i,j,k,c_m3_07_z,c_m3_07_m)\n",
    "                    c_m3_8 = \"{},{},{},C-M3,201908,{},{}\".format(i,j,k,c_m3_08_z,c_m3_08_m)\n",
    "\n",
    "                    f.write(c_m3_7+'\\n'+c_m3_8+'\\n')\n",
    "\n",
    "                    # C-M4\n",
    "                    c_m4_8 = \"{},{},{},C-M4,201908,{},{}\".format(i,j,k,c_m4_08_z,c_m4_08_m)\n",
    "\n",
    "                    f.write(c_m4_8+'\\n')\n",
    "\n",
    "                    # C-C\n",
    "                    c_c_5 = \"{},{},{},C-C,201905,{},{}\".format(i,j,k,c_c_05_z,c_c_05_m)\n",
    "                    c_c_6 = \"{},{},{},C-C,201906,{},{}\".format(i,j,k,c_c_06_z,c_c_06_m)\n",
    "                    c_c_7 = \"{},{},{},C-C,201907,{},{}\".format(i,j,k,c_c_07_z,c_c_07_m)\n",
    "                    c_c_8 = \"{},{},{},C-C,201908,{},{}\".format(i,j,k,c_c_08_z,c_c_08_m)\n",
    "                    f.write(c_c_5+'\\n'+c_c_6+'\\n'+c_c_7+'\\n'+c_c_8+'\\n')\n",
    "\n",
    "                    # M1-C\n",
    "                    m1_c_6 = \"{},{},{},M1-C,201906,{},{}\".format(i,j,k,m1_c_06_z,m1_c_06_m)\n",
    "                    m1_c_7 = \"{},{},{},M1-C,201907,{},{}\".format(i,j,k,m1_c_07_z,m1_c_07_m)\n",
    "                    m1_c_8 = \"{},{},{},M1-C,201908,{},{}\".format(i,j,k,m1_c_08_z,m1_c_08_m)\n",
    "\n",
    "                    f.write(m1_c_6+'\\n'+m1_c_7+'\\n'+m1_c_8+'\\n')\n",
    "\n",
    "                    # M2-C\n",
    "                    m2_c_7 = \"{},{},{},M2-C,201907,{},{}\".format(i,j,k,m2_c_07_z,m2_c_07_m)\n",
    "                    m2_c_8 = \"{},{},{},M2-C,201908,{},{}\".format(i,j,k,m2_c_08_z,m2_c_08_m)\n",
    "\n",
    "                    f.write(m2_c_7+'\\n'+m2_c_8+'\\n')\n",
    "\n",
    "                    # M3-C\n",
    "                    m3_c_8 = \"{},{},{},M3-C,201908,{},{}\".format(i,j,k,m3_c_08_z,m3_c_08_m)\n",
    "\n",
    "                    f.write(m3_c_8+'\\n')\n",
    "\n",
    "                    # M1-M1\n",
    "                    m1_m1_6 = \"{},{},{},M1-M1,201906,{},{}\".format(i,j,k,m1_m1_06_z,m1_m1_06_m)\n",
    "                    m1_m1_7 = \"{},{},{},M1-M1,201907,{},{}\".format(i,j,k,m1_m1_07_z,m1_m1_07_m)\n",
    "                    m1_m1_8 = \"{},{},{},M1-M1,201908,{},{}\".format(i,j,k,m1_m1_08_z,m1_m1_08_m)\n",
    "\n",
    "                    f.write(m1_m1_6+'\\n'+m1_m1_7+'\\n'+m1_m1_8+'\\n')\n",
    "\n",
    "                    # M2-M1\n",
    "                    m2_m1_7 = \"{},{},{},M2-M1,201907,{},{}\".format(i,j,k,m2_m1_07_z,m2_m1_07_m)\n",
    "                    m2_m1_8 = \"{},{},{},M2-M1,201908,{},{}\".format(i,j,k,m2_m1_08_z,m2_m1_08_m)\n",
    "\n",
    "                    f.write(m2_m1_7+'\\n'+m2_m1_8+'\\n')\n",
    "\n",
    "                    # M3-M1\n",
    "                    m3_m1_8 = \"{},{},{},M3-M1,201908,{},{}\".format(i,j,k,m3_m1_08_z,m3_m1_08_m)\n",
    "\n",
    "                    f.write(m3_m1_8+'\\n')\n",
    "print('迁移率数据写入完成！文件位置:{}'.format(os.getcwd()))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
